package com.ocom.srvpamh.service.impl;


import com.ocom.common.constant.MapKey;
import com.ocom.common.enums.ResultEnum;
import com.ocom.common.resp.Result;
import com.ocom.common.utils.ResultUtil;

import com.ocom.srvpamh.feignclient.AiotClientService;
import com.ocom.srvpamh.service.AccessDeviceService;
import com.ocom.srvpamh.vo.SetDeviceStatusBySaasVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
public class AccessDeviceServiceImpl implements AccessDeviceService {
    private final Logger log = LoggerFactory.getLogger(AccessDeviceServiceImpl.class);

    @Autowired
    private AiotClientService aiotClientService;


    @Override
    public Result SetDeviceActBySaas(SetDeviceStatusBySaasVo setDeviceStatusBySaasVo) {
        try {
            Map<String, Object> map = new HashMap<>();
            MapKey mapKey = new MapKey();
            map.put(mapKey.getKey_saasNo(),setDeviceStatusBySaasVo.getSaasNo());
            map.put(mapKey.getKey_agentId(),setDeviceStatusBySaasVo.getAgentId());
            map.put(mapKey.getKey_comId(),setDeviceStatusBySaasVo.getComId());
            map.put(mapKey.getKey_deviceNo(),setDeviceStatusBySaasVo.getDeviceNo());
            map.put(mapKey.getKey_status(),setDeviceStatusBySaasVo.getStatus());
            Result result = aiotClientService.SetMjDeviceStatusBySaas(map);
            if (result.getCode() != 200){
                return ResultUtil.error(result.getCode());
            }
            return result;
        }catch (Exception exception){
            log.error(exception.getMessage());
            return ResultUtil.error(ResultEnum.Err_900);
        }
    }


    @Override
    public Result SetDeviceUnActBySaas(SetDeviceStatusBySaasVo setDeviceStatusBySaasVo) {
        try {
            Map<String, Object> map = new HashMap<>();
            MapKey mapKey = new MapKey();
            map.put(mapKey.getKey_saasNo(),setDeviceStatusBySaasVo.getSaasNo());
            map.put(mapKey.getKey_agentId(),setDeviceStatusBySaasVo.getAgentId());
            map.put(mapKey.getKey_comId(),setDeviceStatusBySaasVo.getComId());
            map.put(mapKey.getKey_deviceNo(),setDeviceStatusBySaasVo.getDeviceNo());
            map.put(mapKey.getKey_status(),0);
            Result result = aiotClientService.SetMjDeviceStatusBySaas(map);
            if (result.getCode() != 200){
                return ResultUtil.error(result.getCode());
            }
            return result;
        }catch (Exception exception){
            log.error(exception.getMessage());
            return ResultUtil.error(ResultEnum.Err_900);
        }
    }
}
